﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WeifenLuo.WinFormsUI.Docking;

namespace FrameWork.WinUI.Controls
{
    public class UIManagerBase
    {
        public EventManagerBase EventManagerBase { get; private set; }
        public DockPanel DockPanel { get; private set; }
        public frmResultList ResultListPanel { get; private set; }

        public UIManagerBase(DockPanel pDockPanel, EventManagerBase pEventManagerBase)
        {
            this.DockPanel = pDockPanel;
            this.EventManagerBase = pEventManagerBase;
        }

        public System.Windows.Forms.Form ParentForm
        {
            get
            {
                return (System.Windows.Forms.Form)this.DockPanel.Parent;
            }
        }

        public string ShowHideResults()
        {
            if (this.ResultListPanel.Visible)
            {
                this.ResultListPanel.Hide();
            }
            else
            {
                this.ResultListPanel.Show();
            }

            return this.ResultListPanel.Visible ? "Hide Results Pane" : "Show Results Pane";
        }

        public void InitResultPanel()
        {
            if (this.ResultListPanel == null)
            {
                this.ResultListPanel = new frmResultList();
                this.ResultListPanel.MdiParent = this.ParentForm;
                this.ResultListPanel.Show(this.DockPanel);
                this.ResultListPanel.DockState = DockState.DockBottom;
                this.ResultListPanel.VisibleState = DockState.DockBottom;
                this.ResultListPanel.UIManager = this;
                this.ResultListPanel.Init();
                this.EventManagerBase.AddResult += new EventManagerBase.DelegateAddResult(this.ResultListPanel.AddResult);
            }
        }

        ~UIManagerBase()
        {
            this.EventManagerBase.AddResult -= new EventManagerBase.DelegateAddResult(this.ResultListPanel.AddResult);
            this.ResultListPanel.Close();
            this.ResultListPanel.Dispose();
            this.ResultListPanel = null;

            this.DockPanel.Dispose();
            this.DockPanel = null;

            this.EventManagerBase = null;
        }
    }
}
